home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / sound / players / waveplay.zoo / dsp.c next >
C/C++ Source or Header  |  1993-07-20  |  3KB  |  109 lines

  1. /*
  2.    This function performs resampling of 8 bit monoral
  3.    PCM samples. The result is placed into the destination
  4.    pointer. The pointer is returned to allow it to be used to
  5.    concatinate multiple segments of data from the same, and or
  6.    different PCM samples. The routine assumes that the 8 bit source
  7.    samples are in MicroSoft Corporation (MSC), unsigned char, 
  8.    WAVE format. And the destination of in Atari, signed char,
  9.    PCM format.
  10.  
  11.   Change History:
  12.  
  13.   11/25/92    Changed floating point to fixed point
  14. */
  15.  
  16. #include "riff.h"
  17. #include "fixed.h"
  18.  
  19. void Resample8bitMono(PCM_Samples *Dest,
  20.                       PCM_Samples *Src,
  21.                       unsigned long Dest_Sample_Rate,
  22.                       unsigned long Src_Sample_Rate)
  23. {
  24. Fixed         delta ;
  25. Fixed         offset ;
  26.  
  27.   delta = fl_fp((double)Src_Sample_Rate/(double)Dest_Sample_Rate) ;
  28.   offset = 0 ;
  29.   while (Dest_Sample_Rate--)
  30.   {
  31.     *Dest->Mono8++ = (unsigned char)((char)Src->Mono8[fp_long(offset)] - 128 ) ;
  32.     offset += delta ;
  33.   }
  34.   return ;
  35. }
  36.  
  37. void Resample16bitMono(PCM_Samples *Dest,
  38.                        PCM_Samples *Src,
  39.                        unsigned long Dest_Sample_Rate,
  40.                        unsigned long Src_Sample_Rate)
  41. {
  42. Fixed         delta ;
  43. Fixed         offset ;
  44.  
  45.   offset = 0 ;
  46. /* 
  47.  *  adjust for bytes per sample 
  48.  */
  49.   Src_Sample_Rate = Src_Sample_Rate / 2l ;
  50.  
  51.   delta = (double)Src_Sample_Rate/(double)Dest_Sample_Rate ;
  52.   while (Dest_Sample_Rate--)
  53.   {
  54.     *Dest->Mono8++ = Src->Mono16[fp_long(offset)].upper ;
  55.     offset += delta ;
  56.   }
  57.   return ;
  58. }
  59.  
  60. void Resample8bitStereo(PCM_Samples *Dest,
  61.                         PCM_Samples *Src,
  62.                         unsigned long Dest_Sample_Rate,
  63.                         unsigned long Src_Sample_Rate)
  64. {
  65. Fixed         delta ;
  66. Fixed         offset ;
  67.  
  68.   offset = 0 ;
  69.   delta = (double)Src_Sample_Rate/(double)Dest_Sample_Rate ;
  70. /* 
  71.  *  adjust for stereo sample 
  72.  */
  73.   Dest_Sample_Rate = Dest_Sample_Rate / 2l ;
  74.   while (Dest_Sample_Rate--)
  75.   {
  76.     (*Dest->Stereo8).left  = (unsigned char)((char)Src->Stereo8[fp_long(offset)].left - 128 ) ;
  77.     (*Dest->Stereo8).right = (unsigned char)((char)Src->Stereo8[fp_long(offset)].right - 128 ) ;
  78.     offset += delta ;
  79.     Dest->Stereo8++ ;
  80.   }
  81.   return ;
  82. }
  83.  
  84. void Resample16bitStereo(PCM_Samples *Dest,
  85.                          PCM_Samples *Src,
  86.                          unsigned long Dest_Sample_Rate,
  87.                          unsigned long Src_Sample_Rate)
  88. {
  89. Fixed         delta ;
  90. Fixed         offset ;
  91.  
  92.   offset = 0 ;
  93. /* 
  94.  *  adjust for bytes per sample 
  95.  */
  96.   Src_Sample_Rate = Src_Sample_Rate / 2l ;
  97.  
  98.   delta = (double)Src_Sample_Rate/(double)Dest_Sample_Rate ;
  99.   while (Dest_Sample_Rate--)
  100.   {
  101.     (*Dest->Stereo8).left  = Src->Stereo16[fp_long(offset)].left.upper ;
  102.     (*Dest->Stereo8).right = Src->Stereo16[fp_long(offset)].right.upper ;
  103.     offset += delta ;
  104.     Dest->Stereo8++ ;
  105.   }
  106.   return ;
  107. }
  108.  
  109.